<?php

class PermalinkController extends Project_Controller{
    
	public function indexAction() {
		$this->initExample();
		
		echo '<br/>$model = new Application_Model_PermalinkExample();<br/>';
		echo '$model->value = \'Post Title 9482 Example\';<br/>';
		echo '$permalink = $model->permalinkFor(\'value\');<br/>';
		$model = new Application_Model_PermalinkExample();
		$model->value = 'Post Title 9482 Example';
		$permalink = $model->permalinkFor('value');
		echo 'New Permalink: <b>'.$permalink.'</b>';
		
		echo '<br/><br/>$dao = new Application_Model_PermalinkExampleDAO();<br/>';
		echo '$list = $dao->search(Frogg_DAO::ALL);';
		$dao = new Application_Model_PermalinkExampleDAO();
    	$list = $dao->search(Frogg_DAO::ALL);        

    	var_dump($list);
    	
    	die;
    }
    
	/**
	 * Creates the database table used in sqlAction() 
	 */
    public function initExample(){
    	echo "
    	<h1>Database Table</h1>
    	<table border='2'>
    		<tr>
    			<td>ID</td>
    			<td>VALUE</td>
    			<td>PERMALINK</td>
    		</tr>
    		<tr>
    			<td>1</td>
    			<td>Hello World</td>
    			<td>hello-world</td>
    		</tr>
    		<tr>
    			<td>2</td>
    			<td>Hello World</td>
    			<td>hello-world-1</td>
    		</tr>
    		<tr>
    			<td>3</td>
    			<td>Hello World</td>
    			<td>hello-world-2</td>
    		</tr>
    		<tr>
    			<td>4</td>
    			<td>Hola Mundo!</td>
    			<td>hola-mundo</td>
    		</tr>
    		<tr>
    			<td>5</td>
    			<td>Hola Mundo!</td>
    			<td>hola-mundo-1</td>
    		</tr>
    		<tr>
    			<td>6</td>
    			<td>Hola Mundo!</td>
    			<td>hola-mundo-2</td>
    		</tr>
    	</table>
    	";
		$model = new Application_Model_PermalinkExample();
		Frogg_DAO::createDB($model);
		$model->value = 'Hello World';
		$model->permalink = $model->permalinkFor('value');
		$model->save();
		$model->permalink = $model->permalinkFor('value');
		$model->save();
		$model->permalink = $model->permalinkFor('value');
		$model->save();
		$model->value = 'Hola Mundo!';
		$model->permalink = $model->permalinkFor('value');
		$model->save();
		$model->permalink = $model->permalinkFor('value');
		$model->save();
		$model->permalink = $model->permalinkFor('value');
		$model->save();
    }
}